/**
 * @description: 参数校验过滤器
 * @version: 0.0.1
 * @author: xiech
 * @Date: 2023-05-31 18:18:52
 */

import { Catch } from '@midwayjs/core';
import { MidwayValidationError } from '@midwayjs/validate';
import { Context } from '@midwayjs/koa';

@Catch(MidwayValidationError)
export class ValidateErrorFilter {

  async catch(err: MidwayValidationError, ctx: Context) {
    // 参数异常的错误
    ctx.logger.error(err?.message ?? err);
    return {
      errorCode: 7000,
      errorMessage: err?.message ?? err,
      success: false,
      data: {},
    };
  }
}
